package leetcode_core.scau_oj;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class IntervalSchedule {
    public static void main(String[] args) {
        int ans = 1;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] points= new int[n][2];
        for(int i =0;i<n;i++){
            int start = scanner.nextInt(),end = scanner.nextInt();
            points[i] = new int[]{start,end};
        }
        Arrays.sort(points, (o1, o2) -> {
            return o1[1] - o2[1];
        });
        int xEnd = points[0][1];//获取最小的end
        for (int[] point : points) {
            int start = point[0];
            if(start >= xEnd){
                xEnd = point[1];
                ans++;
            }
        }
        System.out.println(n-ans);
    }
}
